// init
package api

import (
	"fmt"

	"git.oschina.net/unphp/go-utils/log"
	"git.oschina.net/unphp/go-utils/socket"
	"git.oschina.net/unphp/goweb/model"
	"git.oschina.net/unphp/goweb/utils"
)

var (
	Log       *log.Log //日志
	apiRouter *ApiRoute
)

func init() {
	apiRouter = new(ApiRoute)
	registerRoute()
}

func GetRootPath() string {
	return model.RootPath
}

func GetConfData() *utils.Conf {
	return model.ConfData
}

func GetLog() {

}

func Run() {
	host := GetConfData().Get("core", "sockethost").String()
	protocol := GetConfData().Get("core", "socketprotocol").String()
	socketport := GetConfData().Get("core", "socketport").String()
	socket.AddModulesRoute("app", apiRouter) //添加路由模块
	fmt.Println("api run " + host + ":" + socketport)
	socket.NewSockey(protocol, host, socketport).Run() //运行socket服务
}

func registerRoute() {
	apiRouter.AddRouterController("img", func() ControllerInterface { c := new(ImgController); c.AppController = c; return c })
}
